package cn.hzking.gjmall.adpters.category;

import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;
import java.util.Locale;

import cn.hzking.gjmall.R;
import cn.hzking.gjmall.activitys.second.WebGoodDetailActivity;
import cn.hzking.gjmall.app.Gjmall;
import cn.hzking.gjmall.bean.CategoryListBean;

/**
 * Created by Administrator on 2018/3/6.
 */

public class CateGoryGoodListAdapter extends BaseQuickAdapter<CategoryListBean.DataBean.ItemListBean,BaseViewHolder> {
    public CateGoryGoodListAdapter(int layoutResId, @Nullable List<CategoryListBean.DataBean.ItemListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(final BaseViewHolder helper, final CategoryListBean.DataBean.ItemListBean item) {
        helper.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int itemId = item.getItemId();
                WebGoodDetailActivity.startActivity(mContext,WebGoodDetailActivity.NOMAL,String.valueOf(itemId),"","","");
               /* Intent intent = new Intent(mContext, GoodDetailActivity.class);
                intent.putExtra("itemId",String.valueOf(itemId));
                mContext.startActivity(intent);*/
            }
        });
      // helper.addOnClickListener(R.id.category_goodlist_ll);
       ImageView imageView = helper.getView(R.id.goodlist_goodimage);
       TextView goodTypeText = helper.getView(R.id.good_type);
       TextView goodTitle = helper.getView(R.id.goodlist_title);
       TextView goodPrice = helper.getView(R.id.goodlist_price);
       TextView goodOrderPrice = helper.getView(R.id.goodlist_oldprice);
       TextView goodOrderState = helper.getView(R.id.good_state);
        JSONArray json= JSON.parseArray(item.getPicture());
        String imageUrl = (String) json.get(0);
        Glide.with(mContext).load(Gjmall.getOssHost()+imageUrl).placeholder(R.mipmap.xiangqing).error(R.mipmap.xiangqing).into(imageView);//图片
        goodTypeText.setText(String.valueOf(item.getSellPattern()));//商品状态,是否是商家是自营
        goodTitle.setText(String.valueOf(item.getTitle()));//商品标题
        if(item.isWhetherActivite()){//活动价格
            goodPrice.setText(String.format(Locale.CHINA,"¥ %s",String.valueOf(item.getSnapupPrice())));
            goodOrderState.setVisibility(View.VISIBLE);
        }else {//正常价格
            goodPrice.setText(String.format(Locale.CHINA,"¥ %s",String.valueOf(item.getPrice())));
            goodOrderState.setVisibility(View.GONE);
        }
        goodOrderPrice.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG); //中划线
        goodOrderPrice.setText(String.format(Locale.CHINA,"¥ %s",String.valueOf(item.getAvecostPrice())));//老的价格




    }
}
